<template>
  <!-- 头部盒子 -->

  <div class="header">
    <!-- 标题区域 -->

    <div class="lnner-header">
      <div>
        <h1>欢迎使用《云餐厅》</h1>
        <h2 class="people">商家</h2>
        <!-- <div class="people">
          <el-select v-model="value" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div> -->

        <el-form
          :rules="rules"
          class="login-form"
          ref="form"
          :model="loginform"
        >
          <el-form-item prop="poiId">
            <el-input
              placeholder="请输入商户号"
              type="text"
              v-model="loginform.poiId"
              prefix-icon="el-icon-user"
            ></el-input>
          </el-form-item>
          <el-form-item prop="account">
            <el-input
              placeholder="请输入账号"
              type="text"
              v-model="loginform.account"
              prefix-icon="el-icon-user"
            ></el-input>
          </el-form-item>

          <el-form-item prop="password">
            <el-input
              placeholder="请输入密码"
              type="password"
              v-model="loginform.password"
              prefix-icon="el-icon-circle-check"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" style="width: 100%" @click="denglu"
              >登 录</el-button
            >
          </el-form-item>
          <el-form-item class="forget1 kuai">
            <router-link :to="{ path: '/forget' }" replace
              >忘记密码？</router-link
            >
          </el-form-item>
          <el-form-item class="forget kuai">
            <router-link :to="{ path: '/Register' }" replace>注册</router-link>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      // 账号密码
      loginform: {
        account: "",
        password: "",
        poiId: "",
      },
      // 账号密码-规则
      rules: {
        poiId: [{ required: true, message: "请输入商户号", trigger: "blur" }],
        account: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      // 用户选择
      options: [
        {
          value: "0",
          label: "用户",
        },
        {
          value: "1",
          label: "商家",
        },
      ],
      value: "",
    };
  },

  methods: {
    async denglu() {
      var name = this.loginform.account;
      var password = this.loginform.password;
      var poiId = this.loginform.poiId;

      const { data: res } = await axios.get("/admin/login", {
        params: {
          name: name,
          password: password,
          poiId: poiId,
        },
      });
      if (res.code !== 200) {
        this.$message.error(res.msg);
        return;
      }
      localStorage.setItem("poiId", res.data.poiId);
      localStorage.setItem("door_name", res.data.door_name);
      // // 成功后跳转
      this.$message.success(res.msg);
      localStorage.setItem("token", res.data.token);
      this.$router.push("/home");
    },
  },
  created() {},
};
</script>



<style scoped>
.kuai {
  display: inline-block;
}
.forget1 {
  height: 0;
  float: left;
}

.forget1 a {
  text-decoration: none;
  color: #fff;
}
.forget {
  height: 0;
  float: right;
}

.forget a {
  text-decoration: none;
  color: #fff;
}

.header {
  position: relative;
  background: linear-gradient(60deg, rgb(191 255 98) 0%, rgb(255 179 0) 100%);
  color: rgb(255, 255, 255);
}

.lnner-header {
  height: 740px;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

h1 {
  text-align: center;
  font-family: "Lato", "sans-serif";
  font-weight: 300;
  /* font-spacing:2px; */
  font-size: 48px;
}

h2 {
  text-align: center;
  font-family: "Lato", "sans-serif";
  font-weight: 300;
  /* font-spacing:2px; */
  font-size: 28px;
}
.people {
  margin: 0 auto;
  width: 25%;
}
.login-form {
  margin: 0 auto;
  width: 300px;
  padding-top: 30px;
}

.el-input__inner {
  background-color: rgba(255, 255, 255, 0.7);
  border-radius: 0;
  border: 1px solid #0094ff;
  color: rgba(0, 0, 0, 0.7);
}

.el-input__inner::placeholder {
  color: rgba(0, 0, 0, 0.3);
}

.el-button {
  border-radius: 4px;
}
</style>
